
package app;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public final class Stats {
    static String message;
    static String _currentDate = "";
    static String _currentTime = "";
    static String name = Name.name;
    
   public Stats() throws IOException{
       
   collectionInformation();
   } 
   
    public void collectionInformation() throws IOException{
        
        if(SleepAlert.isReply == false){
        
            currentTime();
            message =_currentTime+" Brak odpowiedzi: "+name;
           // SleepAlert.isReply = true;
        } 
        else {
          currentTime();
            message =_currentTime+" Odpowiedź w czasie: "+name;
        }
    
        if (SleepAlert.wrongReply == true){
          currentTime();
            message =_currentTime+" Błędna odpowiedź: "+name;
            //SleepAlert.wrongReply = false;
        }
        else if (SleepAlert.wrongReply == false && SleepAlert.isReply == true){
          currentTime();
            message =_currentTime+" Poprawna odpowiedź: "+name;
        }
        System.out.println(message);
        currentDate();
        save(_currentDate);
    
    }
    
        public static void currentDate(){
                SimpleDateFormat simpleDateThere = new SimpleDateFormat("yyyy-MM-dd");
                simpleDateThere.setTimeZone( TimeZone.getTimeZone("Poland") );
                _currentDate = simpleDateThere.format(new Date());
              //  System.out.println(_actualTime+": "+ message);
       
    }
        public static void currentTime(){
                SimpleDateFormat simpleDateThere = new SimpleDateFormat("kk:mm:ss");
                simpleDateThere.setTimeZone( TimeZone.getTimeZone("Poland") );
                _currentTime = simpleDateThere.format(new Date());
              //  System.out.println(_actualTime+": "+ message);
       
    }
          
    
       public void save(String name) throws IOException{
            this.name = name;
            BufferedWriter zapis = new BufferedWriter(new FileWriter("Statystyki\\"+name+".txt",true));
            String sep = System.getProperty("line.separator");
            zapis.write(sep+message);
            zapis.close();



        }
    
    
}
